package com.zombieprogrammer.fisicas;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.ChainShape;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.World;
import com.zombieprogrammer.pantallas.Pantalla;

public class Estadio_Fisico {

	private Pantalla pantalla;
	private float alto_p;
	private float ancho_p;
	private float PPM;
	private float zoom;
	private World mundo_fisico;

	public Estadio_Fisico(float x, float y, float alto, float ancho,
			Pantalla pantalla) {
		this.pantalla = pantalla;
		this.alto_p = pantalla.getJuego_base().alto;
		this.ancho_p = pantalla.getJuego_base().ancho;
		this.PPM = pantalla.getJuego_base().PPM;
		this.mundo_fisico = pantalla.getJuego_base().mundo_fisico;
		this.zoom = pantalla.getZoom();
		this.generar_estadio(x, y, alto, ancho);

	}

	public void generar_estadio(float x, float y, float alto, float ancho) {
		float alto_est = alto * zoom / PPM;
		float ancho_est = ancho * zoom / PPM;
		float x_est = x * zoom / PPM;
		float y_est = y * zoom / PPM;

		// System.out.println(alto+"   "+ ancho);

		Vector2 v0 = new Vector2(x_est, y_est);
		Vector2 v1 = new Vector2(x_est, alto_est + y_est);
		Vector2 v2 = new Vector2(x_est + ancho_est, alto_est + y_est);
		Vector2 v3 = new Vector2(x_est + ancho_est, y_est);
		/*
		 * Vector2 v4 = new Vector2(x_est, alto_est + 2); Vector2 v5 = new
		 * Vector2(x_est, alto_est * 2); Vector2 v6 = new Vector2(ancho_est,
		 * alto_est * 2); Vector2 v7 = new Vector2(ancho_est, alto_est + 2);
		 */

		Vector2 vectores[] = { v0, v1, v2, v3, v0 };
		// Vector2 vectores2[] = { v4, v5, v6, v7, v4 };

		BodyDef bodydef = new BodyDef();
		bodydef.type = BodyType.StaticBody;
		bodydef.position.set(0, 0);
		FixtureDef fix = new FixtureDef();

		for (int i = 0; i <= 3; i += 1) {
			ChainShape linea = new ChainShape();
			linea.createChain(new Vector2[] { vectores[i], vectores[i + 1] });

			// definimos el fixture ;
			fix.friction = 0.0f;
			fix.restitution = 0f;
			fix.shape = linea;

			// creamos el piso
			Body piso = mundo_fisico.createBody(bodydef);
			piso.createFixture(fix);
			piso.setUserData("WALL");
			Fixture fixture = piso.createFixture(fix);
			fixture.setUserData("pared");
		}

	}
}
